;
(function() {
  var chart = null;

  var industry = {
    init: function() {
      this.data()
    },
    //统计行业出租面积分布
    data: function() {
      function GetDateStr(AddDayCount) {
        var dd = new Date();
        dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1; //获取当前月份的日期
        var d = dd.getDate();
        return y + "-" + tzero(m) + "-" + tzero(d);
      }
      var data = {
        date: GetDateStr(-1)
      }
      var self = this;
      hlhttp.get({
        url: 'report/acreage_by_industry',
        data: data,
        success: function(data) {
          if (!data.industryList.length) {
            $('.industry-container').html('暂无数据').css('line-height', '465px').addClass('text-center');
            return
          }
          var arr = [];
          for (var i = 0; i < data.industryList.length; i++) {
            arr.push([
              industryType(data.industryList[i].industryType),
              Number(data.industryList[i].acreage)
            ])
          }
          setTimeout(function() {
            self.charts(arr, data.companyCount)
          }, 500);
        }
      })
    },
    //charts
    charts: function(data, count) {
      $(function() {
        $('.industry-container').highcharts({
          colors: [
            '#A88EDA', '#FA83AB', '#F8D86A', '#7FC684', '#69C8FF', '#B6F8DA'
          ],
          title: {
            floating: true,
            useHTML: true,
            style: {
              color: '#333',
              fontWeight: '100',
              top: '50%',
              left: '50%',
              transform: 'translate(0,-50%)',
              textAlign: 'center'
            },
            text: '总企业<p>' + count + '家</p>'
          },
          tooltip: {
            shared: true,
            enabled: true,
            valueDecimals: 2,
            headerFormat: '<span class="font-size:14px">{point.key}</span>',
            pointFormat: '面积: {point.y:.1f}m²',
            borderWidth: 0,
            style: {
              fontSize: '14px'
            }
          },
          plotOptions: {
            pie: {
              enabled: true,
              cursor: 'pointer',
              borderWidth: 2,
              dataLabels: {
                enabled: true,
                formatter: function() {
                  var num = Number(this.percentage).toFixed(2);
                  return num + '%'
                },
                style: {
                  color: '#666',
                  fontFamily: 'Microsoft Yahei',
                  fontSize: '14px'
                }
              },
              size: '75%',
              showInLegend: true
            },
          },
          series: [
            {
              type: 'pie',
              innerSize: '60%',
              name: ' ',
              data: data
            }
          ]
        }, function(c) {
          // 环形图圆心
          var centerY = c.series[0].center[1],
            titleHeight = parseInt(c.title.styles.fontSize);
          c.setTitle({
            y: centerY + titleHeight / 2
          });
          chart = c;
        });
      });
    }
  }
  $(function () {
    industry.init()
  })

  function tzero(n) {
    return n < 10
      ? '0' + n
      : '' + n
  }
  //MI制造业、、、、、、、、、、、、、、、、
  function industryType(state) {
    var result;
    switch (state) {
      case 'MI':
        result = '制造业'
        break;
      case 'JZ':
        result = '能源矿业'
        break;
      case 'PF':
        result = '建筑/房地产'
        break;
      case 'TR':
        result = '环保/公共设施'
        break;
      case 'ZS':
        result = '科研/技术服务'
        break;
      case 'IF':
        result = '农业'
        break;
      case 'JR':
        result = '医药/医疗/保健'
        break;
      case 'HS':
        result = '贸易/运输/物流'
        break;
      case 'ZL':
        result = '金融/投资'
        break;
      case 'SC':
        result = '零售/消费品'
        break;
      case 'JP':
        result = '教育/培训'
        break;
      case 'ED':
        result = '文化/体育/娱乐'
        break;
      case 'WS':
        result = 'IT/通讯/网络'
        break;
      case 'CU':
        result = '专业及商务服务'
        break;
      case 'PS':
        result = '政府/社会组织'
        break;
      case 'ET':
        result = '其他'
        break;
      default:
        result = ''
    }
    return result;
  }
}())
